package com.test.aop;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;

public class MyAopMain {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(MyConfig.class);
		ac.getBean(MyBean.class).println();
	}
}

@Configuration
@EnableAspectJAutoProxy
@Import({MyAspect.class,MyBean.class})
class MyConfig {

}

@Aspect
class MyAspect {
	@Pointcut("execution(* *.println(..))")
	public void out() {

	}

	@Before("out()")
	public void advice() {
		System.out.println(111);
	}
}

@Component
class MyBean {
	public void println() {
		System.out.println(777);
	}
}
